"""
简化版高级功能测试
不依赖外部库的测试
"""

import os
import sys
import json
import tempfile

# 添加项目路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

def test_file_structure():
    """测试文件结构"""
    print("=== 测试文件结构 ===")
    
    # 检查核心文件是否存在
    required_files = [
        "plugin_base.py",
        "plugin_manager.py",
        "config_loader.py",
        "api_context.py",
        "hook_hub.py",
        "__init__.py"
    ]
    
    for file in required_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    # 检查安全模块
    security_files = [
        "security/permissions.py",
        "security/sandbox.py",
        "security/signing.py"
    ]
    
    for file in security_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    # 检查市场模块
    market_files = [
        "market/updater.py"
    ]
    
    for file in market_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    # 检查国际化模块
    i18n_files = [
        "i18n/localization.py"
    ]
    
    for file in i18n_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    # 检查录制模块
    recorder_files = [
        "recorder/operation_recorder.py"
    ]
    
    for file in recorder_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    # 检查文档模块
    docs_files = [
        "docs/generator.py"
    ]
    
    for file in docs_files:
        file_path = os.path.join(os.path.dirname(__file__), file)
        assert os.path.exists(file_path), f"Missing file: {file}"
        print(f"✓ {file}")
    
    print("✓ 文件结构测试通过")


def test_advanced_example():
    """测试高级示例文件"""
    print("\n=== 测试高级示例文件 ===")
    
    example_file = os.path.join(os.path.dirname(__file__), "advanced_example.py")
    assert os.path.exists(example_file), "Missing advanced_example.py"
    print("✓ advanced_example.py")
    
    test_file = os.path.join(os.path.dirname(__file__), "test_advanced_features.py")
    assert os.path.exists(test_file), "Missing test_advanced_features.py"
    print("✓ test_advanced_features.py")
    
    print("✓ 高级示例测试通过")


def test_documentation():
    """测试文档文件"""
    print("\n=== 测试文档文件 ===")
    
    # 检查架构文档
    arch_file = os.path.join(os.path.dirname(__file__), "ARCHITECTURE.txt")
    assert os.path.exists(arch_file), "Missing ARCHITECTURE.txt"
    print("✓ ARCHITECTURE.txt")
    
    # 检查README
    readme_file = os.path.join(os.path.dirname(__file__), "readme.md")
    assert os.path.exists(readme_file), "Missing readme.md"
    print("✓ readme.md")
    
    print("✓ 文档测试通过")


def main():
    """主测试函数"""
    print("插件框架简化版测试")
    print("=" * 50)
    
    try:
        # 运行所有测试
        test_file_structure()
        test_advanced_example()
        test_documentation()
        
        print("\n" + "=" * 50)
        print("🎉 所有测试通过!")
        print("插件框架的文件结构已验证:")
        print("  ✓ 核心组件")
        print("  ✓ 安全模块")
        print("  ✓ 市场模块")
        print("  ✓ 国际化模块")
        print("  ✓ 录制模块")
        print("  ✓ 文档模块")
        print("  ✓ 示例和测试文件")
        print("  ✓ 文档文件")
        
    except Exception as e:
        print(f"\n❌ 测试失败: {e}")
        import traceback
        traceback.print_exc()
        return 1
    
    return 0


if __name__ == "__main__":
    exit(main())